namespace IAM.Interface.Model
{
    using IAM.Interface.Model.Interface;
    using System;
    using System.Collections;
    using System.Reflection;
    using System.Text;
    using System.Xml;

    public class DimensionLevels : AbstractConvertObject, IConvertXml
    {
        private ArrayList _dimensionlevels = new ArrayList();

        public override object ConvertToObject()
        {
            foreach (XmlNode xmlnode in this.CurrentXmlNode.ChildNodes)
            {
                DimensionLevel dimensionlevel = new DimensionLevel();
                dimensionlevel.CurrentXmlNode = xmlnode;
                dimensionlevel = (DimensionLevel) dimensionlevel.ConvertToObject();
                this.Items.Add(dimensionlevel);
            }
            return this;
        }

        public override bool Equals(object obj)
        {
            DimensionLevels dls = null;
            try
            {
                dls = (DimensionLevels) obj;
            }
            catch
            {
                return false;
            }
            bool result = true;
            if (this.Items.Count != dls.Items.Count)
            {
                result = false;
            }
            else
            {
                foreach (object oneofsource in this.Items)
                {
                    DimensionLevel dlsource = (DimensionLevel) oneofsource;
                    result = false;
                    foreach (object oneofobj in dls.Items)
                    {
                        DimensionLevel dlobj = (DimensionLevel) oneofobj;
                        if (dlsource.Equals(dlobj))
                        {
                            result = true;
                            break;
                        }
                    }
                    if (!result)
                    {
                        return result;
                    }
                }
            }
            return result;
        }

        public override int GetHashCode()
        {
            int result = 1;
            PropertyInfo[] pi = base.GetType().GetProperties();
            foreach (PropertyInfo onofpi in pi)
            {
                result += onofpi.GetHashCode();
            }
            return result;
        }

        public int Count
        {
            get
            {
                return this.Items.Count;
            }
        }

        public ArrayList Items
        {
            get
            {
                return this._dimensionlevels;
            }
            set
            {
                this._dimensionlevels = value;
            }
        }

        public string XML
        {
            get
            {
                return (this.XMLBoday + this.XMLFinis);
            }
        }

        public string XMLBoday
        {
            get
            {
                StringBuilder _xml = new StringBuilder();
                _xml.Append("<DimensionLevels");
                _xml.Append(" Count=\"" + this.Count + "\"");
                _xml.Append(" >");
                foreach (object level in this.Items)
                {
                    _xml.Append(((DimensionLevel) level).XML);
                }
                return _xml.ToString();
            }
        }

        public string XMLFinis
        {
            get
            {
                return "</DimensionLevels>";
            }
        }
    }
}
